package com.huluobo.a2203monthdemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.webkit.JavascriptInterface
import com.blankj.utilcode.util.SPUtils
import com.huluobo.a2203monthdemo.news.NewsActivity
import com.huluobo.a2203monthdemo.repair.RepairActivity
import com.huluobo.a2203monthdemo.sign.SignActivity
import com.huluobo.a2203monthdemo.x5.WebViewJavaScriptFunction
import com.huluobo.base.net.Const
import com.tencent.smtt.sdk.WebView

class MainActivity : AppCompatActivity() {
    private lateinit var url: String
    private lateinit var listener: MainWebViewJavaScriptFun
    private lateinit var main_x5view: WebView


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        url = SPUtils.getInstance().getString(Const.PARAM_HOME)
        initWebView()
    }

    private fun initWebView() {
        listener = MainWebViewJavaScriptFun()
        main_x5view = findViewById(R.id.main_x5view)
        main_x5view.loadUrl(url)
        main_x5view.view.overScrollMode = View.OVER_SCROLL_ALWAYS
        main_x5view.addJavascriptInterface(listener, "androidinfo")
    }

    private fun start(clazz: Class<*>) {
        val intent = Intent(this, clazz)
        startActivity(intent)
    }

    inner class MainWebViewJavaScriptFun : WebViewJavaScriptFunction {
        override fun onJsFunctionCalled(tag: String) {
        }

        @JavascriptInterface
        fun androidsign(id: String) {
            start(SignActivity::class.java)
        }

        @JavascriptInterface
        fun androidaddculture(id: String) {
            //打开新闻activity
            start(NewsActivity::class.java)
        }

        @JavascriptInterface
        fun androidparking(id: String?) {
            //车位申请
        }

        @JavascriptInterface
        fun androidapply(id: String?) {
            //我的申请
        }

        @JavascriptInterface
        fun androidvisit(id: String?) {
            //来访预约
        }

        @JavascriptInterface
        fun androidpatrol(id: String?) {
            //巡更管理
        }

        @JavascriptInterface
        fun androidnews(id: String?) {
        }

        @JavascriptInterface
        fun androidnoticelist(id: String?) {
        }

        @JavascriptInterface
        fun androidrepair(id: String?) {
            //维修管理
            start(RepairActivity::class.java)
        }

        @JavascriptInterface
        fun androidaddrepair(id: String?) {
            //添加维修
        }

        @JavascriptInterface
        fun androidaddnotice(id: String?) {
            //公告管理
        }

        @JavascriptInterface
        fun androidculture(id: String?) {
            //文化管理
        }

        @JavascriptInterface
        fun androidnotice(id: String?) {
            //公告管理
        }

        @JavascriptInterface
        fun androidattendance(id: String?) {
            //考勤管理
        }

        @JavascriptInterface
        fun androidproperty(id: String?) {
            //物业审核
        }

        @JavascriptInterface
        fun androidcheckculture(id: String?) {
            //文化审核
        }

        @JavascriptInterface
        fun androidpeople(id: String?) {
            //人资管理
        }
    }
}